/*
 * HackSQL
 * Copyright (C) 2008-2009
 *
 * Authors: Felipe Nascimento Silva Pena
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * $Id: hs_parser_common.h 40 2009-03-28 21:48:03Z felipensp $
 */

#ifndef HACKSQL_PARSER_COMMON_H
#define HACKSQL_PARSER_COMMON_H

#include <hacksql/hs_types.h>

typedef enum {
	IS_FIELD,
	IS_EXPR,
	IS_STRING,
	IS_INTEGER,
	IS_DOUBLE
} hs_value_type;

typedef enum {
	OP_SELECT,
	OP_INSERT,
	OP_UPDATE,
	OP_DELETE,
	OP_CREATE,
	OP_COLUMN,
	OP_COMMIT,
	OP_ROLLBACK
} hs_op;

/* typedef int (*hs_function_cb_t)(int num_args, va_list args); */

typedef struct _hs_node_value {
	union {
		hs_string str;
		hs_uint num;
	} data;
	hs_value_type type;
} hs_node_value;

typedef struct _hs_node {
	hs_op op_type;
	hs_node_value val;
} hs_node;

typedef struct _hs_query_item {
	hs_node_value val;
	hs_string alias;
} hs_query_item;

typedef struct _hs_query {
	hs_op type;
	int distinct;
	int all;
	int num_select_itens;
	int num_table_itens;
	int dual;
	hs_query_item select_itens[50];
	hs_query_item table_itens[10];
} hs_query;

typedef struct _hs_parser_info {
	int socket;
	char *error;
	hs_query *query;
} hs_parser_info;

#define YYSTYPE hs_node

extern int hs_parser_query(hs_parser_info *parser_info, const char *query);
extern void yyerror(hs_parser_info *parser_info, const char* s);
extern int yylex();
extern int yyparse();

#endif
